package com.qc31.monitorlib.ui.adapter

import android.text.Html
import android.widget.ImageView
import android.widget.TextView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.qc31.baselib.utils.loadStringImgError
import com.qc31.baselib.utils.stateColor
import com.qc31.comlib.entity.GpsSimple
import com.qc31.monitorlib.R

/** @Author pc_hfjs @Date 2022/3/8 14:50 @Desc */
class CarsAdapter :
    BaseQuickAdapter<GpsSimple, BaseViewHolder>(R.layout.item_car_info_card) {
    override fun convert(holder: BaseViewHolder, item: GpsSimple) {
        holder.setText(R.id.tvPlate, item.carPlate)
            .setText(R.id.tvSpeed, "${item.speed}km/h")
            .setText(R.id.tvRunStop, item.runStopTime)

        val lrTvState = holder.getView<TextView>(R.id.tvStateAcc)
        val string =
            "<font color=${stateColor(item.state)} >${item.stateCn}</font><font color='#666666'> | ${
                if (item.accTime.isEmpty()) context.getString(
                    R.string.desc_acc_close
                ) else {
                    "ACC${item.accTime}"
                }
            }</font>"
        lrTvState.text = Html.fromHtml(string)
        holder.getView<ImageView>(R.id.ivCarIcon).loadStringImgError(context, item.iconLink)
    }
}